<!DOCTYPE html>
<html>
	<head>
		<meta name="viewport" content="width=device-width, minimum-scale=1, maximum-scale=1">
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" href="../css/font-icons.css">
		<link rel="stylesheet" href="../css/iuapmobile.um.css">
		<link rel="stylesheet" href="../css/iscroll.css" />
		<style>
			#select1_dummy {
				border: none;
				padding-left: 10px;
				text-align: left;
				color: #555;
				padding-bottom: 15px;
				font-size: 17px;
			}
			#select1_dummy:disabled {
				background: #fff;
			}

		</style>

		<script src="../js/summer.js" ></script>
		<script src="../js/jquery.min.js" ></script>
		<script src="../js/Frameworks/iuapmobile.frameworks.ui.js" ></script>
		<script src="../js/Myjs/Push.js"></script>
		<script src="../js/Myjs/yymob.js"></script>
		<style>
			tr {
				background-color: white;
				border-bottom: #bbbbbb 1px solid;
			}
			input {
				outline: medium;
			}
		</style>
		<script src="../js/iscroll.js"></script>
	</head>
	<body style="background-color: white;">
		<div id="Login" class="um-win um-page" >
			<div class="um-content p15">
				<p></p>
				<img src="../img/myimg/login_banner.png" width=100% alt="" class="pl40 pr40 mt40" >

				<div class="um-input-text mt30 tc h40" width="100%" >
					<span style="width:30%;text-align: left;">公司</span>
					<input type="text"  id='select1_dummy'/>
					<select id='select1' onchange="selectedTis(this.id);"></select>
				</div>

				<table width="100%" class=" h100">
					<tr>
						<td style="width:30%;"><label class="" >账号</label></td>
						<td style="width: 70%">
						<input type="text" id="uid" class="form-control" placeholder="请输入用户名" style="border:none;" />
						</td>
					</tr>
					<tr>
						<td style="width: 30%"><label class="" >密码</label></td>
						<td style="width: 70%">
						<input type="password" id="pwd" class="form-control" placeholder="请输入密码" style="border:none;" />
						</td>
					</tr>
				</table>
				<div class="tr f14 mt5 mb10 um-green pr10">

				</div>

				<div class="um-box">
					<div class="tl um-bf1 ">
						<label class="um-check-inline tl">
							<input name="um-checkbox-inline" id="isRember" type="checkbox" value="自动登录" checked>
							<span class="um-icon-checkbox um-css3-vc"></span> <span class="um-black ml5">记住密码?</span> </label>
					</div>
					<div class="tr um-bf1">
						<a href="#LoginServer">服务器配置</a>
					</div>
				</div>

				<button id="login" class="btns mt20 h40">
					登 录
				</button>

				<div yyheight="1"></div>
				<div style="color: #b4b4b4;text-align: center;" class="h10">
					东方天呈©2017 www.dftcgroup.com
				</div>
			</div>
		</div>
		<div class="um-page" id="LoginServer">
			<div class="um-header" >
				<h3>服务器地址配置</h3>
				<a href="#" class="um-back"> 返回 </a>
			</div>
			<div class="um-content">
				<ul class="um-list mt10">
					<li>
						<div class="um-list-item">
							<div class="um-list-item-inner">
								<div class="um-list-item-left pl15" style="-webkit-box-align: start;-webkit-align-self: flex-start;">
									服务器地址
								</div>
								<div class="um-list-item-right">
									<a href="#Login" id="changeToLogin"></a>
									<textarea name="" id="serverAdress" style="height:80px;padding: 10px 0;" class="form-control" placeholder="请在此填写服务器地址"></textarea>
								</div>
							</div>
						</div>
					</li>
				</ul>

				<button class="btns mt10" id="ChangeServerAdress">
					保存
				</button>

			</div>
			<div class="um-footer"></div>
		</div>
		<script>
			$(function() {
				// var curr = new Date().getFullYear();
				var opt = {
					'date' : {
						preset : 'date'
					},
					'select' : {
						preset : 'select'
					}
				};
				$('#select1').scroller('destroy').scroller($.extend(opt['select'], {
					theme : "ios7",
					mode : "scroller",
					display : "bottom",
					animate : ""
				}));

			});
		</script>
	</body>
</html>

<script>
	var deviceid = "";
	var selectdata;
	summerready = function() {
		if(!summer.getStorage("serverAdress")){
			summer.setStorage('serverAdress', "http://t.dftcgroup.com:8989");
		}
		summerreadys();
		if (summer.getStorage("serverAdress")) {
			$("#serverAdress").val(summer.getStorage("serverAdress"));
			inits();
		}
	}
	function inits() {
		//初始化用户数据
		if (summer.getStorage('username')) {
			$("#uid").val(summer.getStorage('username'));
		}
		if (summer.getStorage('password')) {
			$("#pwd").val(summer.getStorage('password'));
			//$("#login").click();
		}
		
		doPost(adressHead.ISjtzImpl, "getBdDoc", {
			dataParm : {
				dostype : "app_gs"
			}
		}, function(data) {
			var selectedIndex = summer.getStorage('selectedIndex');
			var select = document.getElementById("select1");
			var selectText = document.getElementById("select1_dummy");
			selectdata = data;
			for (var i = 0; i < selectdata.length; i++) {
				var option = document.createElement('option');
				option.text = selectdata[i].doc_name;
				select.appendChild(option);
			};

			if (selectedIndex) {
				selectText.value = select.options[selectedIndex].text;
			} else {
				selectText.value = selectdata[0].doc_name;
			}
			//自动登录
			if (summer.getStorage('password')) {
				$("#login").click();
			}
			
		},null,true);
		
	}

	function selectedTis() {
		var obj = document.getElementById("select1");
		var selectText = document.getElementById("select1_dummy");
		var index = obj.selectedIndex;
		var selectjson = selectdata[index];
		//公司名称
		//序号，取当前选中选项的序号
		var val = obj.options[index].text;
		selectText.value = val;
		//缓存用户数据
		summer.setStorage('selectedIndex', index);
		summer.setStorage('selectjson', selectjson);
	}


	$("#login").click(function() {
		var uid = $("#uid").val();
		var pwd = $("#pwd").val();
		var adress = summer.getStorage("serverAdress");
		if (!adress) {
			UM.alert({
				title : '请先配置服务器信息',
				btnText : ["取消", "确定"],
				overlay : true,
				ok : function() {
				}
			});
			return;
		}
		if (!uid) {
			UM.alert({
				title : '请先输入用户名',
				btnText : ["取消", "确定"],
				overlay : true,
				ok : function() {
				}
			});
			return;
		}
		if (!pwd) {
			UM.alert({
				title : '请先输入密码',
				btnText : ["取消", "确定"],
				overlay : true,
				ok : function() {
				}
			});
			return;
		}
		if (deviceid) {
			doPost(adressHead.IUserService, "Login", {
				dataParm : {
					empId : uid,
					password : pwd,
					app_phone_mac : deviceid
				}
			},function(data){
				var result = data;
				var isRember = $("input[type='checkbox']").is(':checked');
				if (result.result == 1) {
				    //记住已选择公司
					if (!(summer.getStorage('selectjson'))) {
						summer.setStorage('selectjson', selectdata[0]);
					};
					//记住用户名
					if (!(summer.getStorage('username')) || summer.getStorage('username') != uid) {
						summer.setStorage('username', uid);
					};
					//记住密码 
					if (isRember) {
						if (!(summer.getStorage('password')) || summer.getStorage('password') != pwd) {
							summer.setStorage('password', pwd);
						};
					} else {
						summer.setStorage('password', "");
					}
					loginDate = new Date();
					var user = result.data;
					summer.setStorage('userinfo', user);//缓存用户信息
					console.log(user);
					summer.openWin({
						id : "home",
						url : "html/home.html",
						isKeep : true,
						"addBackListener":"true"
					});
					$("#pwd").val("");
				} else {
					UM.toast({
						title : '友情提示：',
						text : result.msg,
						duration : 1000
					});
				}
			}, function(err) {
				UM.toast({
					title : '友情提示：',
					text : err.msg,
					duration : 1000
				});
			});
		} else {
			UM.toast({
				title : '友情提示：',
				text : "正在取推送服务，请耐心等待一会儿再试",
				duration : 1000
			});
		}
	});
	$("#nopassword").click(function() {
		UM.alert({
			title : '请联系管理员处理...',
			btnText : ["取消", "确定"],
			overlay : true,
			ok : function() {
			}
		});
		return;
	});

	$("#ChangeServerAdress").click(function() {
		var aa = $("#serverAdress").val();
		if (!aa) {
			UM.alert({
				title : '服务器地址不能为空，如有疑问，请联系管理员获取',
				btnText : ["取消", "确定"],
				overlay : true,
				ok : function() {
				}
			});
			return;
		}
		summer.setStorage('serverAdress', aa);
		$("#changeToLogin").click();
		inits();
	}); 
</script>
<script src="../js/Myjs/Common.js"></script>